package com.opengate.demo.api.config;

import com.opengate.base.contextholder.SpringContextHolder;
import com.opengate.base.redis.RedisHelper;
import com.opengate.base.redis.RedisLockHelper;
import com.opengate.base.redis.RedisSetHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author 曳戈泰尔
 * @version 1.0
 * @description 配置类
 *     <p>Import的作用是在一个类中导入其他类或者配置文件，以方便使用或者集成。
 *     <p>可以用于导入其他Java类、配置文件或者其他Spring组件。
 * @date 2023/4/27 8:59 PM
 */
@Component
@Import({SpringContextHolder.class, RedisHelper.class, RedisLockHelper.class, RedisSetHelper.class})
public class AppConfig {

    /** 设置http请求头 */
    @Bean
    public HttpHeaders httpHeaders() {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Content-type", "application/json;charset=UTF-8");
        return httpHeaders;
    }

    /** 设置http请求超时时间 */
    @Bean
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(10000);
        requestFactory.setReadTimeout(20000);
        return new RestTemplate(requestFactory);
    }
}
